import 'package:flutter/material.dart';
import 'package:flutter_menu/model/product_model.dart';
import 'package:flutter_menu/res/app_color.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'package_controller.dart';

//套餐中固定分组
class GroupFix extends GetView<PackageController> {
  const GroupFix({
    super.key,
    this.title,
    required this.options,
    this.quantity = 1,
  });

  final String? title; // 标题
  final List<Food> options; // 菜品列表
  final int quantity; // 选中数量

  String get quantityString {
    return quantity > 1 ? "x$quantity" : "";
  }

  String specDetail(Spec spec) {
    var optionsJoin =
        spec.options.whereType<SpecOption>().map((item) => item.name).join('/');
    if (optionsJoin.isNotEmpty) {
      optionsJoin = "/$optionsJoin";
    }
    return "${spec.name}$optionsJoin";
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PackageController>(
        id: "groupFix",
        init: PackageController(options: options),
        global: false,
        builder: (PackageController controller) {
          return Obx(() {
            return Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                // 规格选择
                Text(title ?? "",
                    style: TextStyle(
                        fontSize: 26.sp, color: AppColors.text_CA7A2A)),
                ...controller.combineList.map((item) {
                  return Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text("${item.name}$quantityString",
                          style: TextStyle(
                              fontSize: 25.sp,
                              color: AppColors.textInBottomSheet)),
                      Text(specDetail(item.spec),
                          maxLines: 1, // 限制为单行
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                              fontSize: 19.sp, color: AppColors.text_915D44)),
                    ],
                  ).paddingOnly(top: 12.w);
                })
              ],
            );
          });
        });
  }
}
